<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->

<head>
<meta charset="utf-8">
<title>发布卖盘</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="" name="description">
<meta content="" name="author">
<link href="${request.getContextPath()}/Public/assets/admin/css/css.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css">

<link href="${request.getContextPath()}/Public/assets/global/css/components-rounded.css" id="style_components" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/css/plugins.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/admin/css/layout.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/admin/css/themes/default.css" rel="stylesheet" type="text/css" id="style_color">
<link href="${request.getContextPath()}/Public/assets/admin/css/custom.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/admin/css/common.css" rel="stylesheet" type="text/css">



<link rel="shortcut icon" href="${request.getContextPath()}/Public/favicon.ico">
<!--[if lt IE 9]>
<script src="${request.getContextPath()}/Public/assets/global/plugins/respond.min.js"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/excanvas.min.js"></script>
<![endif]-->
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-migrate.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.blockui.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.cokie.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>

<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.sparkline.min.js" type="text/javascript"></script>



<script src="${request.getContextPath()}/Public/assets/global/scripts/metronic.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/admin/scripts/layout.js" type="text/javascript"></script>
<!-- <script src="${request.getContextPath()}/Public/assets/admin/scripts/indexComponent.js" type="text/javascript"></script> -->
<script src="${request.getContextPath()}/Public/assets/admin/scripts/commonUtils.js" type="text/javascript"></script>


<!-- select2控件 -->
<script type="text/javascript" src="${request.getContextPath()}/Public/assets/global/plugins/select2/select2.js"></script>
<script type="text/javascript" src="${request.getContextPath()}/Public/assets/global/plugins/select2/select2_locale_zh-CN.js"></script>
<link href="${request.getContextPath()}/Public/assets/global/plugins/select2/select2.css" rel="stylesheet" type="text/css">

<!-- 日期控件 
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-ui/jquery.ui.datepicker.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-ui/jquery.ui.datepicker-zh-CN.js" type="text/javascript"></script>
-->
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.zh-CN.min.js" type="text/javascript"></script>

<!-- 数据验证 -->
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-validation/js/jquery.validate.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-validation/js/localization/messages_zh.min.js" type="text/javascript"></script>

</head>
<body class="page-header-top-fixed">
<div class="page-header">
	<!--头部开始-->
	<#include "/include/top.html" />
	<!-- 头部信息结束 -->

	<!-- 头部菜单开始 -->
	<#include "/include/top_menu.html" />
	<!-- 头部菜单结束 -->
</div>
<!-- END HEADER -->
<div class="page-container">
	<div class="page-content">
		<div class="container-fluid">
			<!-- 当前位置提示开始 -->
			<ul class="page-breadcrumb breadcrumb">
				<li>
					<a href="#">首页</a><i class="fa fa-circle"></i>
				<li class="active">
					 撮合管理<i class="fa fa-circle"></i>
				<li class="active">
					 发布卖盘池到商城
			</ul>
			<div class="row margin-top-10">
				<div class="col-md-12">
					<div class="portlet light bordered" align="center">
						  <div class="form-group">
						  	  <p align="left"><h3 style="font-weight: bold;">发布报价到商城</h3></p> <br><br>
						  </div>
						  <div class="form-group">
						  	<div class="table-scrollable">
				          		<table class="table table-striped table-bordered table-advance table-hover" id="myTable">
				          			<input type="hidden" id="companyNm" value="${sellPool.companyNm!''}">
						          	<thead>
										<tr>
											<#list itemAttrList  as itemAttr>
												<th  scope="col">
													${itemAttr.name}
												</th> 
											</#list>
											<th  scope="col">
												 计量单位
											</th>
											<th  scope="col">
												 数量(库存)
											</th>
											<th  scope="col">
												 仓库
											</th>
										</tr>
									</thead>
									<tbody>
										<tr>
											<#if sellPool.attrValues?size gt 0>
												<#list  sellPool.attrValues as Value>
													
															<td>
																<#list itemAttrList  as itemAttr>
																	<#if itemAttr.id == Value.attrId>
																			${Value.attrValue}
																	</#if>
																</#list>
															</td>
													 
												</#list>
											</#if>
											<td>
												<#if sellPool.unit == 0>
													吨
												</#if>
												<#if sellPool.unit == 1>
													千克
												</#if>
												
											</td>
											
											<td>
												${sellPool.quantity?c}
											</td>
												
											<td>
												${sellPool.wareNm!''}
											</td>
										</tr>
									</tbody>
								</table>
			          		</div>
						  </div>
					  <form class="form-horizontal" id="dataForm">
					      <input type="hidden" name="gatid" value="${sellPool.gatid}">
					  	  <input type="hidden" name="quantity" value="${sellPool.quantity?c}">
					  	  <input type="hidden" name="wareId" value="${sellPool.wareId}">
					  	  <input type="hidden" name="sellpoolid" value="${sellPool.id}">
					  	  <input type="hidden" id="contact" name="contact">
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">商城用户名</label>
						    <div class="col-sm-2">
						      <!-- <input  class="form-control"  width="200" id="account"  name="account"/> -->
						      <select class="form-control"  style="width: 250px" id="account"  name="totalmallid " onchange="viewContact(this)">						      
						      </select>
						    </div>
						    <div id="" class="col-sm-2">
						      <p><span>联系人:</span><span id="contact1" style="color: RED"></span></p>
						    </div>
						    <div id="telephone" class="col-sm-2">
						      <p><span>电话：</span><span id="telephone1" style="color: RED"></span></p>
						    </div>
						  </div>
					
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">挂牌有效期：</label>
						    <div class="col-sm-2">
						      <select  class="form-control" id="terms" name="terms" onchange="changeTerm(this)">
							      <option value="0">当天</option>
							      <option value="1">本周</option>
							      <option value="2">本月</option>
							      <option value="3">三月</option>
							      <option value="4">半年</option>
							      <option value="5">指定时间</option>
						      </select>
						    </div>
						    <div id="appointDate" class="col-sm-2" style="display: none">
					      		<input  id="optionalDate" class="form-control" name="termdateString">
					    	</div> 
						  </div>
						  <!-- <#list itemAttrList as itemAttr>
								  	<div class="form-group">
									    <label  class="col-sm-2 control-label">${itemAttr.name}：</label>
									    <div class="col-sm-2">
									      <select  class="form-control" id="inputPassword3" name="itemsID">
									      <#if itemAttr.optionsValue??>
						  					<#list itemAttr.optionsValue as optionsValue>
									      		<option value="${optionsValue!''}">${optionsValue!''}</option>
									      	</#list>
						  				  </#if>
									      </select>
									    </div>
								  	</div>
						  </#list> -->
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">交货方式：</label>
						    <div class="col-sm-2">
						    	<select class="form-control" id="deliverytype"  name="deliverytype">
						    		<option value="0">卖方送货</option>
						       		<option value="1">买方自提</option>
						    	</select>
						    </div>
						  </div>
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">交货日期：</label>
						    <div class="col-sm-4">
						    	<table>
						    		<tr>	
										<td>
										<div class="md-radio">
											<input type="radio" id="qw" name="deliverydatetype" class="md-radiobtn" value="0" onclick="choseThis(this)">
											<label for="qw">
											<span class="inc"></span>
											<span class="check"></span>
											<span class="box"></span>
											</label>
										</div>
										</td>	
										<td nowrap>
											指定
										</td>					    		
						    			<td>
						    				<div class="input-group input-medium date-picker input-daterange" data-date-format="yyyy-mm-dd" >
											    <input id="deliverydateString" name="deliverydateString" class="form-control" style="font-size: 13px;" type="text" disabled="disabled">
											</div>
			
						    			</td>
						    			
						    			<td nowrap>
						    				为交货日
						    			</td>
						    		</tr>
						    		<tr>
						    			<td>
						    			<div class="md-radio">
											<input type="radio" id="qw1" name="deliveryDateType" class="md-radiobtn" value="1" onclick="choseThis(this)">
											<label for="qw1">
											<span class="inc"></span>
											<span class="check"></span>
											<span class="box"></span>
											</label>
										</div>
										</td>
										
										<td nowrap>
											指定
										</td>						    		
						    			<td>
						    				<div class="input-group input-medium date-picker input-daterange" data-date-format="yyyy-mm-dd" >
											    <input id="datebeginString" name="datebeginString" class="form-control" style="font-size: 13px;" type="text" disabled="disabled">
											    <span class="input-group-addon">到</span>
											    <input id="dateendString" name="dateendString" class="form-control" style="font-size: 13px;" type="text" disabled="disabled">
											</div>
						    			</td>
						    		</tr> 
						    		<tr>	
										<td>
											<div class="md-radio">
												<input type="radio" id="qw2" name="deliveryDateType" class="md-radiobtn" value="2" onclick="choseThis(this)">
												<label for="qw2">
												<span class="inc"></span>
												<span class="check"></span>
												<span class="box"></span>
												</label>
											</div>
										</td>	
										<td nowrap>
											成交后
										</td>					    		
						    			<td>
						    				<input type="text" id="days" class="form-control" name="days" disabled="disabled">
						    			</td>
						    			<td nowrap>
						    				日内交货
						    			</td>
						    		</tr>
						    	</table>
							 </div>
						  </div>
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">磅差(‰)：</label>
						    <div class="col-sm-2">
						       <input type="text" class="form-control" id="pounddiff" name="pounddiff">
						    </div>
						  </div>
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">起订量：</label>
						    <div class="col-sm-2">
						       <input type="text" class="form-control"  value="0" id="beginordercount" name="beginordercount"
						       	onfocus="if(value == 0){value=''}"   
                				onblur="if(value==''){value=0}"/>
						    </div>
						    <div class="col-sm-2">
						   		    吨，超出部分按
						    </div>
						    <div class="col-sm-2">
						     
						      <input value="0" id="step" name="step" type="text">
						    </div>
						    <div class="col-sm-2">
						     	（吨）整数倍递增
						    </div>
						  </div>
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">结算方式：</label>
						    <div class="col-sm-2">
						       <select class="form-control"  id="payment" name="payment">
						    		<option value="0">现汇</option>
						       		<option value="1">承兑(三月)</option>
						       		<option value="2" >承兑(六月)</option>
						    	</select>
						    </div>
						  </div>
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">价格：</label>
						    <div class="col-sm-2">
						       <input type="text" class="form-control" name="price">
						    </div>
					    	<div class="col-sm-2">
						      <input  class="form-control"  type="checkbox" id="webLogin"/>有色网代收付
						      <input id="surrogate" value="0" name="surrogate" type="hidden">
						    </div> 
						  </div>
					
 						  <div class="form-group">
						    <div class="col-sm-offset-2 col-sm-2" align="center">
						    	<button id="notSavetButton"  onclick="quit()" type="button" class="btn green pull-left">
									返回 <i class="m-icon-swapright m-icon-white"></i>
								</button>
						      	<button type="button"  id="savetButton" class="btn green pull-center">
									提交<i class="m-icon-swapright m-icon-white"></i>
								</button>
						    </div>
						  </div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- 底部开始 -->
<#include "/include/foot.html" />
<!-- 底部结束 -->
</body>
<script>
	
jQuery(document).ready(function() {
	 
	 $("#optionalDate").datepicker({
	   	 	language: "zh-CN",
	        autoclose: true,//选中之后自动隐藏日期选择框
	        clearBtn: true,//清除按钮
	        todayBtn: true,//今日按钮
	        format: "yyyy-mm-dd",//日期格式
	        startDate:new Date()
		});
	 
	 //商城
	 $("#account").empty();
		$.ajax({
			url : "${request.getContextPath()}/dealMake/queryCompany.do",
			type : "post",
			dataType:"json",
			async: false,
			data :{"companyName":$("#companyNm").val()}, //联动查询的字符
			success : function(data) {
			 	var jsonData = eval(data);//接收到的数据转化为JQuery对象，由JQuery为我们处理 
				$("#account").append("<option value=''>--请选择--</option>");
				$.each(jsonData, function(index, item) {
					$("#account").append(
							"<option value='"+item.userid+"'myAttr1='"+item.truename+"'myAttr2='"+item.mobile+"'>" + item.account + "</option>");
				}); 
			}
		});
	 
	 
    //select2
   $("#account//").select2({//妈的 
	   language: "zh_CN",
       placeholder: "搜索商城用户",//文本框的提示信息
      // minimumInputLength: 2,//至少输入n个字符，才去加载数据
       allowClear: true, //是否允许用户清除文本信息
       ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
    	   url : "${request.getContextPath()}/dealMake/queryCompany.do",
           dataType: 'json',//接收的数据类型
           type : "post",
           data: function (term, page) {//在查询时向服务器端传输的数据
               return {
                   companyName: $("#companyNm").val(), //联动查询的字符
                   page: 10 //一次性加载的数据条数
               };
           },
           results: function (data, page) { // parse the results into the format expected by Select2.
               // since we are using custom formatting functions we do not need to alter remote JSON data
               var realNames = new Array();    
                    for (var i = 0; i < data.length; i++) {
                         realNames.push({id: data[i].userid, text: data[i].account,truename:data[i].truename,mobile:data[i].mobile});
                         
                  }
               return {results: realNames};
           }
       },
       formatResult: resultFormatResult, // omitted for brevity, see the source of this page
       formatSelection: resultFormatSelection,  // omitted for brevity, see the source of this page
       dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
       escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
    });
	   Metronic.init(); // init metronic core componets
	   Layout.init(); // init layout
	});
	recordDate();
	//初始化日期
	function recordDate() {
		var nowDate = new Date();
        //$('#date-picker').attr("date-date",nowDate.getFullYear()+"/"+parseInt(nowDate.getMonth()+1)+"/"+nowDate.getDate());
        $('.date-picker').datepicker({
    	    autoclose: true	   
    	});
	}
	
	//返回
	$("#notSavetButton").bind("click",function(){
		$.ajax({
			url : "${request.getContextPath()}/dealMake/returnSellOrder.do",
			type : "post",
			async: false,
			success : function(result) {
				    if(result.code=="success"){
					      		window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
					}else {
						
			   		}
				}
		});
	});
	//复选框问题
	$("#surrogate").val("2");
	//有色网代付，默认不选中，不选中值为0,选中值为1
	$("#webLogin").bind("click",function(){
		if($(this).attr('checked')){
			$("#surrogate").val("1");
		}else{
			$("#surrogate").val("2");
		}
	
	});
	
	//表单提交
	$("#savetButton").bind("click",function(){
		if(!$("#dataForm").validate({
			//数据验证
			rules:{
				pounddiff:{
					required: true,
					digits:true //整数
				} ,
				step:{
					required: true,
					digits:true //整数
				} ,
				beginordercount:{
					required: true,
					digits:true //整数
				} ,
				price:{
					required: true,
					number:true //数字(可以是小数和整数)
				} ,
			}
		}).form()){
			return;
		} 
		//console.log($("#dataForm").serialize());
		
		if ($("#account").val() == null || $("#account").val() == "") {
			alert("没有商城，不能发布!");
			window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
		}else{
			alert($("#dataForm").serialize());
			 $.ajax({
				url: "${request.getContextPath()}/dealMake/addSellPoolPublish.do",
				type : "post",
				dataType:"json",
				data:$("#dataForm").serialize(),
				async: false,
				success : function(result) {
				   	if(result.code=="success"){
				      		window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
					}else {
						alert("发布失败!");
						window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
			   		}
			   }
			});   
		}
	});

	
	function resultFormatResult(medata) {
        return medata.text; 
	} 
	      
	function resultFormatSelection(medata) {
		//追加联系人数据
			document.getElementById("contact1").innerHTML = medata.truename;
			$("#contact").val(medata.truename);
			document.getElementById("telephone1").innerHTML = medata.mobile;
	        return medata.text; 
	} 
	
	
	function quit(){
  		window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
	}
	
	//指定时间
	function changeTerm(obj){
		if(obj.value == 5){
			$("#appointDate").css("display","inline");
		}
	}
	
	//单选框选中事件
	function choseThis(obj){
		if(obj.id == "qw"){
			document.getElementById("deliverydateString").disabled=false;
			$("#datebeginString").val("");
			$("#dateendString").val("");
			$("#days").val("");
			document.getElementById("datebeginString").disabled=true;
			document.getElementById("dateendString").disabled=true;
			document.getElementById("days").disabled=true;
		}
		if(obj.id == "qw1"){
			document.getElementById("datebeginString").disabled=false;
			document.getElementById("dateendString").disabled=false;
			$("#deliverydateString").val("");
			$("#days").val("");
			document.getElementById("deliverydateString").disabled=true;
			document.getElementById("days").disabled=true;
			
		}
		if(obj.id == "qw2"){
			document.getElementById("days").disabled=false;
			$("#datebeginString").val("");
			$("#dateendString").val("");
			$("#deliverydateString").val("");
			document.getElementById("datebeginString").disabled=true;
			document.getElementById("dateendString").disabled=true;
			document.getElementById("deliverydateString").disabled=true;
		}
		
	}
	//下拉框选中触发
	function viewContact(object){
		 	var obj=document.getElementById("account");    
		    var index=obj.selectedIndex;   
		    var myAttr1=obj.options[index].getAttribute("myAttr1");//联系人
		    var myAttr2=obj.options[index].getAttribute("myAttr2");//电话
		    
		  //追加联系人数据
			document.getElementById("contact1").innerHTML = myAttr1;
			$("#contact").val(myAttr1);
			document.getElementById("telephone1").innerHTML = myAttr2;
	}
</script>
</html>

